package fun.werfamily.wf.goods.core.domain.service.impl;

import fun.werfamily.wf.goods.core.domain.dto.response.GoodsCategoryDTO;
import fun.werfamily.wf.goods.core.domain.service.GoodsCategoryService;
import fun.werfamily.wf.goods.core.infrastructure.dataobject.GoodsCategoryDO;
import fun.werfamily.wf.goods.core.infrastructure.mapper.GoodsCategoryMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2023-05-02 16:44
 * @Description:
 */
@Service
@Slf4j
public class GoodsCategoryServiceImpl implements GoodsCategoryService {

    @Resource
    private GoodsCategoryMapper goodsCategoryMapper;

    @Override
    public List<GoodsCategoryDTO> listGoodsCategory() {
        List<GoodsCategoryDTO> goodsCategoryDTOList =new ArrayList<>();
        List<GoodsCategoryDO> goodsCategoryDOS = goodsCategoryMapper.listAllCategory();
        if (!CollectionUtils.isEmpty(goodsCategoryDOS)) {
            for (GoodsCategoryDO goodsCategoryDO : goodsCategoryDOS) {
                GoodsCategoryDTO goodsCategoryDTO = new GoodsCategoryDTO();
                BeanUtils.copyProperties(goodsCategoryDO, goodsCategoryDTO);
                goodsCategoryDTOList.add(goodsCategoryDTO);
            }
        }
        return goodsCategoryDTOList;
    }
}
